<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/vue.js"></script>
</head>
<!-- v-for遍历 -->

<body>
    <div id="app">
        <ul>
            <!-- 注意：跟key不跟index 默认跟index 因为在前面插入元素会造成每一项的索引发生变化-->
            <li v-for="(item, index) in teachers" :key="item.id">{{item.id}},{{item.name}},{{item.age}} <input type="text"></li>
        </ul>
       
        <button @click="addTeacher()">添加一条数据</button>
    </div>

    <script>
        new Vue({
            el: '#app',
            data: {
                teachers: [
                    { id: "001", name: "张三", age: 18 },
                    { id: "002", name: "李四", age: 28 },
                    { id: "003", name: "王五", age: 38 },
                    { id: "004", name: "赵六", age: 48 },
                ]
            },
            methods: {
                addTeacher() {
                       this.teachers.unshift({ id: "005", name: "田七", age: 58 });
                },
            }
        })
    </script>
</body>

</html>